{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2023-12-26T06:37:14.054575600Z",
     "start_time": "2023-12-26T06:37:14.039434400Z"
    }
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "df = pd.read_csv('../static/data/info_pre.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "outputs": [
    {
     "data": {
      "text/plain": "[{'value': 485, 'name': '银行'},\n {'value': 394, 'name': '配套纯熟'},\n {'value': 394, 'name': '医院'},\n {'value': 390, 'name': '便利店'},\n {'value': 380, 'name': '装修交付'},\n {'value': 374, 'name': '学校'},\n {'value': 365, 'name': '公园'},\n {'value': 264, 'name': '购物中心'},\n {'value': 244, 'name': '商业街'},\n {'value': 209, 'name': '人车分流'},\n {'value': 205, 'name': '现房'},\n {'value': 191, 'name': '品牌开发商'},\n {'value': 169, 'name': '小型社区'},\n {'value': 146, 'name': '大户型'},\n {'value': 122, 'name': 'VR看房'},\n {'value': 112, 'name': '大型社区'},\n {'value': 92, 'name': '高绿化率'},\n {'value': 83, 'name': '大平层'},\n {'value': 79, 'name': '绿色住宅'},\n {'value': 79, 'name': '轨交房'},\n {'value': 77, 'name': '生态绿地'},\n {'value': 77, 'name': '大阳台'},\n {'value': 70, 'name': '地铁沿线'},\n {'value': 54, 'name': '主卧套房'},\n {'value': 54, 'name': '小户型'},\n {'value': 47, 'name': '多轨交'},\n {'value': 41, 'name': '旅游地产'},\n {'value': 40, 'name': '品质好房'},\n {'value': 38, 'name': '自带商业'},\n {'value': 38, 'name': '线上不打烊'},\n {'value': 34, 'name': '动静分离'},\n {'value': 34, 'name': '户型方正'},\n {'value': 34, 'name': '金牌物业'},\n {'value': 33, 'name': '商住公寓'},\n {'value': 33, 'name': '双卫生间'},\n {'value': 33, 'name': '低单价'},\n {'value': 32, 'name': '办公首选'},\n {'value': 32, 'name': '自持物业'},\n {'value': 32, 'name': '智能住宅'},\n {'value': 30, 'name': '低总价'},\n {'value': 29, 'name': '山景地产'},\n {'value': 29, 'name': '刚需直选'},\n {'value': 28, 'name': '30日内开盘'},\n {'value': 27, 'name': '商圈热盘'},\n {'value': 27, 'name': '客餐厅相连'},\n {'value': 27, 'name': '厨卫全明'},\n {'value': 26, 'name': '地铁上盖'},\n {'value': 25, 'name': '深圳西部'},\n {'value': 25, 'name': '玄关入户'},\n {'value': 24, 'name': '海景地产'}]"
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tags = [j for i in df['tags'].values for j in i.split('|')]\n",
    "df_tags = pd.DataFrame(tags, columns=['tags'])\n",
    "data = [{'value': i[1], 'name': i[0]} for i in df_tags.value_counts().reset_index().head(50).values]\n",
    "data"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-12-26T06:37:14.072365500Z",
     "start_time": "2023-12-26T06:37:14.057575Z"
    }
   },
   "id": "c342d3f7be94525"
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "outputs": [
    {
     "data": {
      "text/plain": "[{'value': 91, 'name': '光明区'},\n {'value': 207, 'name': '南山区'},\n {'value': 62, 'name': '坪山区'},\n {'value': 229, 'name': '宝安区'},\n {'value': 56, 'name': '盐田区'},\n {'value': 76, 'name': '福田区'},\n {'value': 76, 'name': '罗湖区'},\n {'value': 152, 'name': '龙华区'},\n {'value': 302, 'name': '龙岗区'}]"
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "region_list = ['光明区', '南山区', '宝安区', '坪山区', '盐田区', '福田区', '罗湖区', '龙华区', '龙岗区']\n",
    "data_list = df[df['region'].isin(region_list)][['title', 'region']].groupby(\n",
    "    'region').count().reset_index().values.tolist()\n",
    "data = [{'value': i[1], 'name': i[0]} for i in data_list]\n",
    "data"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-12-26T06:37:14.090230400Z",
     "start_time": "2023-12-26T06:37:14.073364Z"
    }
   },
   "id": "65261766804bb6b4"
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "outputs": [
    {
     "data": {
      "text/plain": "[['住宅', 855],\n ['公寓', 224],\n ['标准写字楼', 108],\n ['别墅', 43],\n ['临街店铺', 40],\n ['社区底商', 10],\n ['商务园区', 9],\n ['商业街', 5],\n ['商业独栋', 4]]"
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dwelling_type_list = df[df['dwelling_type'] != '无']['dwelling_type'].value_counts().reset_index().values.tolist()\n",
    "label = [i[0] for i in dwelling_type_list]\n",
    "data = [i[1] for i in dwelling_type_list]\n",
    "{\n",
    "    'label':label,\n",
    "    'data':data\n",
    "}"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-12-26T06:39:59.958538500Z",
     "start_time": "2023-12-26T06:39:59.952907900Z"
    }
   },
   "id": "10275bebecfd4dfc"
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "outputs": [
    {
     "data": {
      "text/plain": "        price                                                           \\\n        count          mean           std      min       25%       50%   \nregion                                                                   \n光明区      87.0  46198.770115  13028.500609  21000.0  40876.50   44454.0   \n南山区     201.0  98634.412935  24124.851216  46200.0  86605.00   98098.0   \n坪山区      62.0  37926.612903   6050.477774  16500.0  36135.00   39108.0   \n大鹏区      22.0  39252.863636  10959.342708  23800.0  29137.50   37000.0   \n宝安区     218.0  60620.853211  18688.262589  28000.0  46425.00   58500.0   \n深圳区      19.0  17835.052632  13923.449403    290.0  12250.00   13158.0   \n深汕区      12.0  12018.916667   6363.284007    383.0  10374.75   11453.0   \n盐田区      55.0  51216.981818   8204.889286  36000.0  45950.00   50380.0   \n福田区      75.0  94318.066667  21065.972654  48000.0  75295.50  100400.0   \n罗湖区      75.0  68160.920000  12561.912382  36000.0  60268.00   68240.0   \n龙华区     150.0  63112.726667  19747.802050   2098.0  52000.00   65061.5   \n龙岗区     292.0  43834.797945  11157.584007    120.0  39500.00   40494.0   \n\n                             \n              75%       max  \nregion                       \n光明区      47357.00  105000.0  \n南山区     105860.00  268000.0  \n坪山区      39252.00   65130.0  \n大鹏区      45075.00   59987.0  \n宝安区      73987.75  147000.0  \n深圳区      22645.00   59987.0  \n深汕区      12500.00   28560.0  \n盐田区      54050.00   85000.0  \n福田区     108774.00  135000.0  \n罗湖区      79600.00   89800.0  \n龙华区      72136.00  160000.0  \n龙岗区      48254.75   88046.0  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead tr th {\n        text-align: left;\n    }\n\n    .dataframe thead tr:last-of-type th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr>\n      <th></th>\n      <th colspan=\"8\" halign=\"left\">price</th>\n    </tr>\n    <tr>\n      <th></th>\n      <th>count</th>\n      <th>mean</th>\n      <th>std</th>\n      <th>min</th>\n      <th>25%</th>\n      <th>50%</th>\n      <th>75%</th>\n      <th>max</th>\n    </tr>\n    <tr>\n      <th>region</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>光明区</th>\n      <td>87.0</td>\n      <td>46198.770115</td>\n      <td>13028.500609</td>\n      <td>21000.0</td>\n      <td>40876.50</td>\n      <td>44454.0</td>\n      <td>47357.00</td>\n      <td>105000.0</td>\n    </tr>\n    <tr>\n      <th>南山区</th>\n      <td>201.0</td>\n      <td>98634.412935</td>\n      <td>24124.851216</td>\n      <td>46200.0</td>\n      <td>86605.00</td>\n      <td>98098.0</td>\n      <td>105860.00</td>\n      <td>268000.0</td>\n    </tr>\n    <tr>\n      <th>坪山区</th>\n      <td>62.0</td>\n      <td>37926.612903</td>\n      <td>6050.477774</td>\n      <td>16500.0</td>\n      <td>36135.00</td>\n      <td>39108.0</td>\n      <td>39252.00</td>\n      <td>65130.0</td>\n    </tr>\n    <tr>\n      <th>大鹏区</th>\n      <td>22.0</td>\n      <td>39252.863636</td>\n      <td>10959.342708</td>\n      <td>23800.0</td>\n      <td>29137.50</td>\n      <td>37000.0</td>\n      <td>45075.00</td>\n      <td>59987.0</td>\n    </tr>\n    <tr>\n      <th>宝安区</th>\n      <td>218.0</td>\n      <td>60620.853211</td>\n      <td>18688.262589</td>\n      <td>28000.0</td>\n      <td>46425.00</td>\n      <td>58500.0</td>\n      <td>73987.75</td>\n      <td>147000.0</td>\n    </tr>\n    <tr>\n      <th>深圳区</th>\n      <td>19.0</td>\n      <td>17835.052632</td>\n      <td>13923.449403</td>\n      <td>290.0</td>\n      <td>12250.00</td>\n      <td>13158.0</td>\n      <td>22645.00</td>\n      <td>59987.0</td>\n    </tr>\n    <tr>\n      <th>深汕区</th>\n      <td>12.0</td>\n      <td>12018.916667</td>\n      <td>6363.284007</td>\n      <td>383.0</td>\n      <td>10374.75</td>\n      <td>11453.0</td>\n      <td>12500.00</td>\n      <td>28560.0</td>\n    </tr>\n    <tr>\n      <th>盐田区</th>\n      <td>55.0</td>\n      <td>51216.981818</td>\n      <td>8204.889286</td>\n      <td>36000.0</td>\n      <td>45950.00</td>\n      <td>50380.0</td>\n      <td>54050.00</td>\n      <td>85000.0</td>\n    </tr>\n    <tr>\n      <th>福田区</th>\n      <td>75.0</td>\n      <td>94318.066667</td>\n      <td>21065.972654</td>\n      <td>48000.0</td>\n      <td>75295.50</td>\n      <td>100400.0</td>\n      <td>108774.00</td>\n      <td>135000.0</td>\n    </tr>\n    <tr>\n      <th>罗湖区</th>\n      <td>75.0</td>\n      <td>68160.920000</td>\n      <td>12561.912382</td>\n      <td>36000.0</td>\n      <td>60268.00</td>\n      <td>68240.0</td>\n      <td>79600.00</td>\n      <td>89800.0</td>\n    </tr>\n    <tr>\n      <th>龙华区</th>\n      <td>150.0</td>\n      <td>63112.726667</td>\n      <td>19747.802050</td>\n      <td>2098.0</td>\n      <td>52000.00</td>\n      <td>65061.5</td>\n      <td>72136.00</td>\n      <td>160000.0</td>\n    </tr>\n    <tr>\n      <th>龙岗区</th>\n      <td>292.0</td>\n      <td>43834.797945</td>\n      <td>11157.584007</td>\n      <td>120.0</td>\n      <td>39500.00</td>\n      <td>40494.0</td>\n      <td>48254.75</td>\n      <td>88046.0</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "region_group = df[df['price']>0][['region','price']].groupby('region').describe()\n",
    "region_group"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-12-26T08:13:10.748658600Z",
     "start_time": "2023-12-26T08:13:10.689920400Z"
    }
   },
   "id": "b6441bb1d76cfc8e"
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "outputs": [
    {
     "data": {
      "text/plain": "[['product', '售罄', '在售'],\n ['罗湖区', 71184, 65203],\n ['龙岗区', 44395, 40365],\n ['光明区', 45703, 47284],\n ['南山区', 98996, 96578],\n ['宝安区', 62983, 56661],\n ['龙华区', 62486, 64068],\n ['坪山区', 37113, 38135],\n ['深汕区', 21794, 10010],\n ['福田区', 94756, 93008],\n ['盐田区', 51363, 52106],\n ['大鹏区', 39564, 37517],\n ['深圳区', 21998, 12111]]"
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_mean = df[(df['sale_status'] != '待售') & (df['sale_status'] != '无') & (df['price']>0)][['region','price','sale_status']]\n",
    "data = [['product','售罄','在售']]\n",
    "data += [[i]+[round(j[1]) for j in df_mean[df_mean['region'] == i][['price','sale_status']].groupby('sale_status').mean().reset_index().values] for i in df['region'].unique()]\n",
    "data"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-12-26T07:31:39.842906200Z",
     "start_time": "2023-12-26T07:31:39.804016800Z"
    }
   },
   "id": "eb4de13378ddc4b1"
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "outputs": [
    {
     "data": {
      "text/plain": "{'label': ['3室', '4室', '2室', '1室', '5室', '6室', '9室', '7室'],\n 'data': [663, 493, 396, 126, 122, 22, 3, 1]}"
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "unit_type_list =[j for i in df[df['unit_type'] != '无']['unit_type'] for j in i.split('|')]\n",
    "df_unit_type = pd.DataFrame(unit_type_list,columns=['unit_type'])\n",
    "df_unit_type = df_unit_type.value_counts().reset_index()\n",
    "label = [i[0] for i in df_unit_type.values]\n",
    "data = [i[1] for i in df_unit_type.values]\n",
    "{\n",
    "    'label':label,\n",
    "    'data':data\n",
    "}"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-12-26T07:41:00.600740700Z",
     "start_time": "2023-12-26T07:41:00.589092800Z"
    }
   },
   "id": "afc365ae00407a7b"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "80d30b61b498b9bc"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
